<?php


namespace App\Service;

use Illuminate\Database\Eloquent\Builder;

abstract class CommonService {
    protected $instance;

    public function lst(array $conditions) :Builder {
        return $this->instance->getRecords($conditions);
    }

    public function add(array $info) {
        return $this->instance->updateOrCreate(['id'=>$info['id']??0],$info);
    }

    public function del($ids) {
        if(!is_array($ids)){
            $ids = [$ids];
        }
        $this->instance->whereIn('id',$ids)->delete();
        return responseSuccess();
    }

    public function detail($id) {
        return $this->instance->find($id);
    }

    public function update($ids,$col,$val) {
        return is_array($ids)?$this->instance->whereIn('id',$ids)->update([$col=>$val]):
            $this->instance->where(['id'=>$ids])->update([$col=>$val]);
    }
}
